import instance from '../utils/request'
import { Message } from 'element-ui'

// 得到所有楼栋分页
async function getBuilds (page, limit, search) {
  return await instance.get('/build/getBuildPage?page=' + page + '&limit=' + limit + '&buildName=' + search).then(data => {
    return data
  }).catch(() => {
    Message.error('没有权限,请先登录')
  })
}

// 得到所有楼栋
async function getBuildALls () {
  return await instance.get('/build').then(data => {
    return data
  }).catch(() => {
    Message.error('没有权限,请先登录')
  })
}
// 修改提交
async function editBuild (build) {
  return await instance({
    url: '/build',
    method: 'put',
    data: build
  }).then(res => {
    return res
  }).catch(() => {
    Message.error('删除失败,服务器错误!')
  })
}

// 添加提交
async function addBuild (build) {
  return await instance({
    url: '/build',
    method: 'post',
    data: build
  }).then(res => {
    return res
  }).catch(() => {
    Message.error('删除失败,服务器错误!')
  })
}

// 删除
async function deleteBuild (buildId) {
  return await instance.delete('/build/' + buildId).then(res => {
    return res
  }).catch(() => {
    Message.error('删除失败,服务器错误!')
  })
}

// 批量删除
async function deleteAllBuild (Ids) {
  return await instance.delete('/build/all/' + Ids).then(res => {
    return res
  }).catch(() => {
    Message.error('删除失败,服务器错误!')
  })
}

export default {
  getBuilds,
  deleteBuild,
  editBuild,
  deleteAllBuild,
  addBuild,
  getBuildALls

}
